package ac.svn.accesscontrol.ui;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import ac.svn.accesscontrol.store.SVNGroup;
import ac.svn.accesscontrol.store.SVNUser;
import ac.svn.accesscontrol.utils.Utility;

public class UserTreeCellRenderer extends DefaultTreeCellRenderer 
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public UserTreeCellRenderer()
	{
		
	}

	public Component getTreeCellRendererComponent(JTree tree,
		      Object value,boolean sel,boolean expanded,boolean leaf,
		      int row,boolean hasFocus) {
		        super.getTreeCellRendererComponent(tree, value, sel, 
		          expanded, leaf, row, hasFocus);
		        Object nodeObj = ((DefaultMutableTreeNode)value).getUserObject();
		        // check whatever you need to on the node user object
		        if(nodeObj instanceof SVNGroup)
		        {
		        	SVNGroup svnGroup = (SVNGroup) nodeObj;
		        	setToolTipText(svnGroup.getTooltipText()); 
		        	setIcon(new ImageIcon(Utility.getImage("images/groupSmall.png")));
		        }
		        else if(nodeObj instanceof SVNUser)
		        {
		        	SVNUser svnUser = (SVNUser) nodeObj;
		        	setToolTipText(svnUser.getTooltipText());
		        	setIcon(new ImageIcon(Utility.getImage("images/userSmall.png")));
		        }
		        else
		        {
		        	setToolTipText("-----------");
		        	setIcon(new ImageIcon(Utility.getImage("images/Subversion.png")));
		        }
		        return this;
		    }

}
